﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Net;
using com.lover.common;
using System.IO;
using com.lover.astd.common.model;
using com.lover.common.http;

namespace com.lover.astd.common.partner.impl
{
    public class NiuaLogin : LoginImplBase
    {
        public NiuaLogin() : base() { }
        public override bool alwaysNeedVerifyCode() { return true; }
        public override string getAlwaysCaptchaImageUrl() { return "http://www.niua.com/seccode.php"; }
        public override LoginResult login(ref List<Cookie> cookies, string verify_code = null, string extra = null)
        {
            LoginResult result = new LoginResult();
            logging();
            
            if (verify_code == null)
            {
                buildAlwaysVerifyResult(ref result, ref cookies);
                return result;
            }

            string loginurl = "http://www.niua.com/login/";
            string data = String.Format("refer=http%3A%2F%2Fwww.niua.com%2Findex.php&name={0}&password={1}&seccode={2}&keeplive=1", 
                _username, _md5_password_lower, verify_code);
            HttpResult resp = TransferMgr.doPostPure(loginurl, data, ref cookies);
            if (resp == null) { result.StatusCode = LoginStatusCode.FailInLogin; return result; }
            string retstr = resp.getContent();
            if (retstr.Contains("/login/"))
            {
                result.StatusCode = LoginStatusCode.FailInLogin;
                return result;
            }

            string redirecturl = String.Format("http://www.niua.com/playGame/code/astd{0}/", _acc.ServerId);

            processRedirect(redirecturl, result, ref cookies);
            return result;
        }
    }
}
